/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2018/11/24 Time: 22:25
 *
 *
 */

import React, {Component} from 'react';
import {
  View,
  Image,
  Text,
  TouchableOpacity
} from 'react-native';
import PropTypes from 'prop-types';
import {styles} from './TitleViewComponent.Style';

export default class TitleViewComponent extends Component {

  static propTypes = {
    titleName: PropTypes.string.isRequired, // 左侧标题
    displayDescription: PropTypes.bool,
    onClick: PropTypes.func // 右侧点击事件
  }

  static defaultProps = {
    displayDescription: false,
    onClick: null
  }

  render() {
    return (
      <View style={styles.container}>

        <View style={styles.leftView}>
          <View style={{width: 20, height: 20, backgroundColor: '#112233'}}/>
        </View>

        <View style={styles.centerView}>
          <Text style={styles.centerTextView}>
            {this.props.titleName}
          </Text>
        </View>

        {
          this.props.displayDescription &&
          <TouchableOpacity activeOpacity={0.8} onPress={this.props.onClick}>
            <View style={styles.rightView}>
              <View style={{width: 20, height: 20, backgroundColor: '#112233'}}/>
            </View>
          </TouchableOpacity>
        }

      </View>
    )
  }
}